package com.teama4.shop.controller;

import com.teama4.shop.domain.Admin;
import com.teama4.shop.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/Admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("")
    public String index() {
        return "/admin/index";
    }

    @PostMapping("/first")
    public String first(int id, String password, Model model){
        Admin admin = new Admin();
        admin.setId(id);
        admin.setPassword(password);
        if(adminService.findAdmin(admin)==1) {
            admin = adminService.selectByPrimaryKey(id);
            String admin_name = admin.getName();
            model.addAttribute("admin_name", admin_name);
            return "/admin/admin-home-page";
        } else {
            return "/common/404";
        }
    }
}
